package com.naiterui.ehp.bs.doctor.dao.impl;

import com.naiterui.ehp.bs.doctor.dao.IBeforePasswordDao;
import com.naiterui.ehp.bs.doctor.domain.DrBeforePassword;
import com.naiterui.ehp.bs.doctor.repository.IBeforePasswordRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author guoyongxiang
 * @date 2019-06-22 14:56
 * @since 1.0.0
 */
@Component
public class AdBeforePasswordDaoImpl  implements IBeforePasswordDao {

    @Autowired
    private IBeforePasswordRepository beforePasswordRepository;

    @Override
    public void save(DrBeforePassword drBeforePassword) {
        beforePasswordRepository.save(drBeforePassword);
    }

    @Override
    public void removeById(Long id) {
        beforePasswordRepository.removeById(id);
    }

    @Override
    public List<DrBeforePassword> findLastBeforePasswordLimit(Long userId, int limit) {
        Pageable pageable = PageRequest.of(0,limit, Sort.by("createdAt").descending());
        return beforePasswordRepository.findByUserId(userId, pageable);
//        return super.findByLimit("from DrBeforePassword where userId=? order by createdAt desc", limit, userId);
    }
}
